//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import complaintItem from '../comm/complaintItem.vue';
import { scrollMixin } from "utils/mixin";
export default {
  name:'',
  //import引入的组件需要注入到对象中才能使用
  components: {complaintItem},
  mixins: [scrollMixin], //加载更多
  data() {
  return {
    isLoadMore: true,
    page: 1,
    totalPage: 0,
    proposalList:[],
    sharedata:{}
  };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    initData() {
      this.page = 1;
      this.proposalList = [];
    },
    getData() {
      let that = this;
      $http.get("plugin.help-center.frontend.controllers.center.share").then(response => {
        if (response.result == 1) {
          this.sharedata = response.data;
          that.fun.wxShare(
            "",
            {},
            {
              title: this.sharedata.title,
              imgUrl: this.sharedata.icon,
              description: this.sharedata.description
            },
            data => {
              // if (!that.fun.isTextEmpty(data.shop && data.shop.shop)) {
              //   that.initCservice(data.shop.shop.cservice); //客服重新赋值
              // }
            }
          );
          // that.initCservice("");
        }
      });
    },
    proposalData() {
      let query = {
        page:this.page
      }
      $http.post("plugin.help-center.frontend.controllers.proposal.index.list", query, "加载中..").then(response => {
        if (response.result == 1) {
          let res = response.data;
          this.isLoadMore = true;
          this.totalPage = res.last_page;
          if (!this.totalPage) {
            this.page = 0;
          }
          this.proposalList = res.data;
        } else {
          this.page = this.page - 1;
          this.isLoadMore = false;
          this.$dialog.alert({
            message: response.msg
          });
        }
      });
    },
     //获取更多数据
     getMoreData() {
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.page >= this.totalPage) {
        return;
      } else {
        this.page = this.page + 1;
        let query = {
          page:this.page
        }
        $http.post("plugin.help-center.frontend.controllers.proposal.index.list", query, "加载中").then(
          res => {
            this.isLoadMore = true;
            if (res.result === 1) {
              let myData = res.data.data;
              this.proposalList = [...this.proposalList, ...myData]; //数组拼接
            } else {
              this.page = this.page - 1;
              this.isLoadMore = false;
            }
          },
          function(response) {
            console.log("response", response);
            // error callback
          }
        );
      }
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
  
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
  
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {
    this.initData();
    this.getData();
    this.proposalData();
  }, //如果页面有keep-alive缓存功能，这个函数会触发
}